const A = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderListArr: [
      {
        name: '全部',
        val: ''
      }, {
        name: '待提货',
        val: '0'
      }, {
        name: '已提货',
        val: '1'
      }
    ],
    orderArrSty: 0,
    orderStatus: '',
    total: 10,
    pageIndex:1
  },
  // 点击切换 
  changeOrderArr(e) {
    let orderArrSty = A.C(e).index;
    let orderStatus = A.C(e).val;
    console.log(orderArrSty);
    this.setData({
      orderArrSty,
      orderStatus,
      pageIndex:1
    });
    this.getOrders(1);
  },
  // 支付订单列表
  getOrders(index) {
    let config = {
      orderStatus: this.data.orderStatus,
      pageNum: index,
      pageSize: 10
    }
    A.updata.getOrders(config).then(res => {
      this.setData({
        ordersList: res.list
      })
    })
  },
  toOrderDetail(e) {
    let id = A.C(e).id;
    wx.navigateTo({
      url: `/pages/mall/orderDetail/orderDetail?id=${id}`
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.setData({ orderStatus: options.type, orderArrSty: options.index })
    this.getOrders(1);
  },

  onTouchStart(e) {
    console.log(e);
    this.touchStart(e);
  },
  onTouchMove(e) {
    console.log(e);
    this.touchMove(e);
  },
  onTouchEnd(e) {
    console.log(e);
    var _b = this, direction = _b.direction, deltaX = _b.deltaX, offsetX = _b.offsetX;
    console.log('方向:' + direction);
  },
  touchStart(event) {
    var touch = event.touches[0];
    this.direction = '';
    this.deltaX = 0;
    this.deltaY = 0;
    this.offsetX = 0;
    this.offsetY = 0;
    this.startX = touch.clientX;
    this.startY = touch.clientY;
  },
  touchMove(event) {
    var touch = event.touches[0];
    this.deltaX = touch.clientX - this.startX;
    this.deltaY = touch.clientY - this.startY;
    this.offsetX = Math.abs(this.deltaX);
    this.offsetY = Math.abs(this.deltaY);
    this.direction =
      this.offsetX > this.offsetY
        ? 'horizontal'
        : this.offsetX < this.offsetY
          ? 'vertical'
          : '';
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.switchTab({
      url: '/pages/my/my'
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let pageIndex = this.data.pageIndex;
    let total = this.data.total;
    if (pageIndex >= total) return;
    pageIndex++;
    this.getOrders(pageIndex);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})